<template>
<div>
  <div style="margin: 20px;"></div>
  <el-form :label-position="labelPosition" label-width="80px" :model="form">
    <el-form-item label="名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="价格">
      <el-input v-model="form.price"></el-input>
    </el-form-item>
    <el-select v-model="form.cate" placeholder="请选择">
      <el-option
        v-for="i in catelist"
        :label="i.name"
        :value="i.id"
        :key="i.id"
      >
      </el-option>
    </el-select>
    <br><el-button type="primary" round @click="addgoods">添加</el-button>
  </el-form>
</div>
</template>

<script>
export default {
  name: "addgoods",
  data(){
    return{
      labelPosition: 'right',
      form:{
        name:'',
        price:'',
        cate:''
      },
      catelist:[]
    }
  },
  methods:{
    addgoods(){
      console.log(this.form)
      this.$axios.post('goods/',this.form)
      .then(resp=>{
        console.log(resp.data)
        alert('添加成功')
      })
    },
    getCatelist(){
      this.$axios.get('cate/')
      .then(resp=>{
        console.log(resp.data)
        this.catelist = resp.data
      })
    }
  },
  created() {
    this.getCatelist();
  }
}
</script>

<style scoped>

</style>
